<!--
 * @author gaohailan
 -->
<template>
  <div class="app-container reasonable-answer">
    <el-collapse-transition>
      <div v-show="searchshow" class="common-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model="listQuery.collectName" clearable placeholder="按项目名称进行搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <div class="common-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">更多筛选条件<i class="el-icon-arrow-down" /></span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="common-search separate">
        <div class="common-search-inner">
          <el-row :gutter="20">
            <!-- <el-col :span="6">
              <div class="search-inner-item">
                <div class="item-label">解决方案</div>
                <el-input v-model="listQuery.plan" clearable class="filter-item" style="width: 100%;" placeholder="请输入解决方案搜索" />
              </div>
            </el-col> -->
            <!-- <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">是否分组</div>
                <el-select v-model="search.isGroupBy" placeholder="请选择">
                  <el-option key="0" :value="0" label="是"/>
                  <el-option key="1" :value="1" label="否"/>
                </el-select>
              </div>
            </el-col> -->
            <el-col :span="6">
              <div class="search-inner-item">
                <div class="item-label">项目名称</div>
                <el-input v-model="search.collectName" style="width: 90%;" class="filter-item" placeholder="请输入项目名称搜索" />
              </div>
            </el-col>
            <el-col :span="6">
              <div class="search-inner-item">
                <div class="item-label">真实姓名</div>
                <el-input v-model="search.propounder" style="width: 90%;" class="filter-item" placeholder="请输入真实姓名搜索" />
              </div>
            </el-col>
            <el-col :span="6">
              <div class="search-inner-item">
                <div class="item-label">单位名称</div>
                <el-input v-model="search.orgName" style="width: 90%;" class="filter-item" placeholder="请输入单位名称搜索" />
              </div>
            </el-col>
            <el-col :span="18">
              <div class="common-search-btn">
                <el-button type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
                <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
                <span class="common-search-more" @click="searchshow = !searchshow">精简筛选条件<i class="el-icon-arrow-up" /></span>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-collapse-transition>
    <div class="common-btn">
      <div class="btn-title">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="待审核" name="0" />
          <el-tab-pane label="已审核" name="1" />
          <!-- <el-tab-pane label="已驳回" name="2"></el-tab-pane> -->
        </el-tabs>
      </div>
      <div class="btn-btns">
        <el-button style="margin-left: 10px;" @click="handleExport">导出</el-button>
        <el-button style="margin-left: 10px;" @click="handleExports">统计汇总导出</el-button>
      </div>
    </div>
    <div class="table">
      <el-table
        v-loading="listLoading"
        :data="honorList"
        class="tableScope"
        :header-cell-style="rowClass"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="collectName" label="项目名称" show-overflow-tooltip width="200" />
        <el-table-column prop="propounder" label="建议人" show-overflow-tooltip width="200" />
        <el-table-column prop="propounder" label="姓名" show-overflow-tooltip width="200" />
        <el-table-column  prop="auditState" label="单位审核状态" show-overflow-tooltip width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.auditState=='1'">二级单位审核</span>
            <span v-if="scope.row.auditState=='2'">集团审核</span>
            <span v-if="scope.row.auditState=='3'">不通过</span>
            <span v-if="scope.row.auditState=='4'">已审核</span>
          </template>
        </el-table-column>
        <el-table-column prop="orgName" label="单位" show-overflow-tooltip width="200" />
        <el-table-column v-if="activeName==1" prop="adoptState" label="是否采纳" show-overflow-tooltip width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.adoptState=='1'">是</span>
            <span v-if="scope.row.adoptState=='2'">否</span>
          </template>
        </el-table-column>
          <el-table-column v-if="activeName==1" prop="adoptState" label="是否实施" show-overflow-tooltip width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.implementState=='1'">是</span>
            <span v-if="scope.row.implementState=='2'">否</span>
          </template>
        </el-table-column>
          <el-table-column v-if="activeName==1" prop="adoptState" label="是否金点子" show-overflow-tooltip width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.excellenceState=='1'">是</span>
            <span v-if="scope.row.excellenceState=='2'">否</span>
            <span v-if="scope.row.excellenceState=='3'">否</span>
          </template>
        </el-table-column>
          <el-table-column v-if="activeName==1" prop="adoptState" label="是否优秀" show-overflow-tooltip width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.excellenceState=='1'">否</span>
            <span v-if="scope.row.excellenceState=='2'">是</span>
            <span v-if="scope.row.excellenceState=='3'">否</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button v-if="activeName==0 && scope.row.unitsState !=1 && userInfo.remark == '二级单位管理员'|| userInfo.remark == '二级单位分会管理员' " type="text" size="mini" @click="handleCheck(scope.row)">审核</el-button>
            <el-button v-if="activeName==0 && pf == 1 ||userInfo.remark == '合理化建议审核员' " type="text" size="mini" @click="handleCheck(scope.row)">审核</el-button>
            <el-button type="text" size="mini" @click="handleDownload(scope.row)">下载</el-button>
               </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
    <el-dialog v-if="classifyDialogVisible" :visible.sync="classifyDialogVisible" title="审核" center width="600px" top="25vh">
      <div class="view-content">
        <ul>
          <li>
            <p>
              <span class="label-style">项目名称：</span>
              {{ viewDetail.collectName }}</p>
          </li>
          <li>
            <p>
              <span class="label-style">建议人：</span>
              {{ viewDetail.propounder }}</p>
          </li>
          <li>
            <p>
              <span class="label-style">岗位：</span>
              {{ viewDetail.station }}</p>
          </li>
          <li>
            <p>
              <span class="label-style">建议原因：</span>
              {{ viewDetail.adviceReason }}</p>
          </li>
          <li>
            <p>
              <span class="label-style">解决方案或措施：</span>
            </p>
            <p v-html="viewDetail.solution" />
          </li>
          <li>
            <p>
              <span class="label-style">建议的实施效果：</span>
            </p>
            <p v-html="viewDetail.adviceEffect" />
          </li>
        </ul>
      </div>
      <el-form ref="dataForm" v-loading="formloading" :model="temp"  class="dataForm" label-position="right" label-width="140px">
        <el-form-item  v-if="this.userInfo.remark == '二级单位管理员'|| userInfo.remark == '二级单位分会管理员'" label="选择状态" prop="recommendedState">
          <el-radio v-model="temp.recommendedState" :label="1">向集团推荐</el-radio>
          <el-radio v-model="temp.recommendedState" :label="2">不推荐</el-radio>
        </el-form-item>
        <el-form-item v-if="this.userInfo.remark == '二级单位管理员' || userInfo.remark == '二级单位分会管理员'" label="审查意见" prop="reviewOpinions">
          <el-input v-model="temp.reviewOpinions" type="textarea" :rows="3" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item  v-if="this.userInfo.remark == '二级单位管理员' || userInfo.remark == '二级单位分会管理员'&& this.temp.recommendedState != 2" label="是否实施" prop="implementState">
          <el-radio v-model="temp.implementState" :label="1">是</el-radio>
          <el-radio v-model="temp.implementState" :label="2">否</el-radio>
        </el-form-item>
        <el-form-item v-if="this.userInfo.remark == '二级单位管理员' || userInfo.remark == '二级单位分会管理员'&& this.temp.recommendedState != 2"  label="是否采纳" prop="isGood">
          <el-radio v-model="temp.adoptState" :label="1">是</el-radio>
          <el-radio v-model="temp.adoptState" :label="2">否</el-radio>
        </el-form-item>
        <el-form-item v-if="this.userInfo.remark == '平台管理员'||this.userInfo.remark == '合理化建议审核员'"  label="选择状态" prop="excellenceState">
          <el-radio v-model="temp.excellenceState" :label="1">评为金点子</el-radio>
          <el-radio v-model="temp.excellenceState" :label="2">评为优秀</el-radio>
          <el-radio v-model="temp.excellenceState" :label="3">不评</el-radio>
        </el-form-item>
        <div style="
    margin-left: 180px;
     margin-top: -25px;
" v-if="this.userInfo.remark == '平台管理员'" class="one">
          <span>{{viewDetail.jdzNum}}/10</span>
          <span style="
    margin-left: 92px;
   
">{{viewDetail.yxNum}}/50</span>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="classifyDialogVisible = false">取 消</el-button>
        <el-button v-if="this.userInfo.remark == '二级单位管理员'|| userInfo.remark == '二级单位分会管理员'" style="padding: 8px 30px;" type="primary" @click="submitFn">确 认</el-button>
        <el-button v-if="this.userInfo.remark == '平台管理员'||this.userInfo.remark == '合理化建议审核员'" style="padding: 8px 30px;" type="primary" @click="submitFns">确 认</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
// import { suggestPlanWaitQueryPage, getUserInfo, suggestPlanVerifys, suggestPlanVerify, suggestPlanView } from '@/api/reasonable/index'
import { mapGetters } from 'vuex'
import Cookies from 'js-cookie'
export default {
  name: 'ReasonableAnswer',
  components: { Pagination },
  data() {
    return {
      searchshow: true,
      listLoading: false,
      total: 0,
      listQuery: {
        page: 1,
        pageSize: 10,
        collectName: '',
        suggestId: ''
      },
      search: {
        isGroupBy: '',
        collectName: '',
        propounder: '',
        orgName: ''
      },
      multipleSelection: [],
      honorList: [],
      deptId:[],
      activeName: '0', //
      classifyDialogVisible: false,
      formloading: false,
      temp: {
        dataId: '',
        recommendedState: 1,
        reviewOpinions: '',
        auditState: 1,
        implementState: 1,
        adoptState:"",
        adoptState: 1,
        excellenceState: 1,
      },
      pd:"",
      pf:0,
      handleSee: false,
      viewDetail: {}
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    this.listQuery.suggestId = this.$route.query.id
    // this.getInfo()
    
  },
  methods: {
     getInfo() {
      return new Promise((resolve, reject) => {
        getUserInfo().then((res) => {
          this.userInfo = res.data.data;
          this.pd = this.userInfo.remark;
          
          this.deptId =JSON.parse(this.userInfo.extend1)
          this.getList()
          if (this.pd == '平台管理员') {
            this.pf = 1
            console.log(this.pf,"11111");
          }else{
            console.log(this.pf,"123");
            return
          }
        });
      });
    },
    getView(id) {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.1)'
      })
      return new Promise((resolve, reject) => {
        suggestPlanView({ id: id }).then((res) => {
          loading.close()
          this.viewDetail = res.data.data
        }).catch(error => {
          loading.close()
          reject(error)
        })
      })
    },
    submitFn() {
      if (this.temp.recommendedState == 1 && this.temp.reviewOpinions =='' ) {
        this.$message({
              message: '请输入审查意见！',
              type: 'warning'
            });
            return
      }
      if (this.temp.recommendedState == 2) {
        this.temp.auditState = 3
      }else{
        this.temp.auditState = 2
      }
      var temp = {
        id: this.temp.dataId,
        recommendedState: this.temp.recommendedState,
        auditState: this.temp.auditState,
        unitsState:1,
        implementState: this.temp.implementState,
        adoptState: this.temp.adoptState,
        reviewOpinions:this.temp.reviewOpinions
      }
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.1)'
          })
          return new Promise((resolve, reject) => {
            suggestPlanVerify(temp).then((res) => {
              loading.close()
              this.classifyDialogVisible = false
              this.$notify({
                title: '成功',
                message: res.msg || '操作成功',
                type: 'success',
                duration: 2000
              })
              this.getList()
            }).catch(error => {
              loading.close()
              reject(error)
            })
          })
        }
      })
    },  
    submitFns() {
      
      var temp = {
        id: this.temp.dataId,
        state:1,
        excellenceState: this.temp.excellenceState,
        unitsState:1,
      }
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.1)'
          })
          return new Promise((resolve, reject) => {
            suggestPlanVerifys(temp).then((res) => {
              loading.close()
              this.classifyDialogVisible = false
              this.$notify({
                title: '成功',
                message: res.msg || '操作成功',
                type: 'success',
                duration: 2000
              })
              this.getList()
            }).catch(error => {
              loading.close()
              reject(error)
            })
          })
        }
      })
    },
    handleCheck(row) {
      this.getView(row.id)
      this.temp = {
        dataId: row.id,
        recommendedState: 2,
        reviewOpinions: '',
        auditState: 1,
        implementState: 1,
        adoptState: 1,
        excellenceState: 1,
      }

      this.classifyDialogVisible = true
    },
    handleClick(tab, event) {
      this.activeName = '0'
      const _this = this
      setTimeout(function() {
        _this.activeName = tab.name
        _this.getList()
      }, 100)
    },
    handleExport() {
      // window.open('/API-BACKEND/admin/SuggestActive/export?id=' + this.listQuery.suggestId)
      window.open('/API-BACKEND/admin/rationalizationCollect/exportPlan?collectId=' + this.listQuery.suggestId)
    },
    handleExports() {
      window.open('/API-BACKEND/admin/rationalizationCollect/exportGood?id=' + this.listQuery.suggestId)
    },
    handleDownload(row) {
      console.log(row)
      window.open('/API-BACKEND/admin/rationalizationCollect/rationalizationCollect?id=' + row.id)
    },
    rowClass({ row, rowIndex }) {
      return {
        padding: '5px 0',
        height: '20px',
        background: 'rgba(247,247,248,1)'
      }
    },
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.collectName = ''
      for (const i in this.search) {
        this.search['' + i + ''] = ''
      }
      this.listQuery.page = 1
      this.listQuery.pageSize = 10
      this.listQuery.suggestId = this.$route.query.id
      this.getList()
    },
    handleDeletes() {
      const arr = []
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach(item => {
          arr.push(item.id)
        })
        var ids = arr.join(',')
      } else {
        this.$message({
          message: '请选择需要删除的数据！',
          type: 'warning'
        })
      }
    },
    getList(obj) {
      this.listLoading = true
      if (this.userInfo.remark == '二级单位管理员') {
        var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.pageSize,
        state:this.activeName,
        collectId : this.listQuery.suggestId,
        orgId:this.userInfo.orgId ,
        deptId:this.deptId[0].id,
        propounder:this.search.propounder,
        orgName:this.search.orgName
      }
      }else{
        var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.pageSize,
        state:this.activeName,
        collectId : this.listQuery.suggestId,
        orgId:this.userInfo.orgId,
      }
      }
      
      if (this.searchshow) {
        query['collectName'] = this.listQuery.collectName
      } else {
        // query['isGroupBy'] = this.search.isGroupBy
        query['collectName'] = this.search.collectName
        query['propounder'] = this.search.propounder
        query['orgName'] = this.search.orgName
      }
      if (this.activeName == 0) {
        return new Promise((resolve, reject) => {
          suggestPlanWaitQueryPage(query).then(response => {
            this.honorList = response.data.data.rows
            this.total = response.data.data.total
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          }).catch(error => {
            reject(error)
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          })
        })
      } else {
        return new Promise((resolve, reject) => {
          suggestPlanWaitQueryPage(query).then(response => {
            this.honorList = response.data.data.rows
            this.total = response.data.data.total
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          }).catch(error => {
            reject(error)
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          })
        })
      }
    },
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
  $dark_gray: #bfced6;
  $dark_main: #18A5FD;
  $mainColor: #18A5FD;
  .reasonable-answer {
    
    .common-search {
      background-color: #fff;
      padding: 0 20px;
      margin-bottom: 10px;
      .svg-container {
        padding: 0;
        color: $dark_gray;
        vertical-align: middle;
        display: inline-block;
        &_login {
          font-size: 20px;
        }
      }
      .search-input {
        width: 60%;
        position: relative;
        &:after {
          content: "";
          position: absolute;
          left: -25px;
          right: 0;
          bottom: 8px;
          height: 1px;
          background: rgba(226, 227, 232, 1);
        }
        input {
          outline: none;
          background: transparent;
          border: none;
          outline: medium;
          padding: 0;
          &:focus {
            outline: none;
            background-color: transparent;
          }
        }
      }
      .common-search-btn {
        display: inline-block;
        float: right;
        .el-button.is-round {
          padding: 10px 30px;
          margin-right: 34px;
        }
        .course-search-more {
          font-size: 14px;
          font-weight: 500;
          color: $dark_main;
          cursor: pointer;
          margin-left: 10px;
        }
      }
      &.merge {
        height: 50px;
        line-height: 50px;
      }
      &.separate {
        .course-search-inner {
          padding-top: 10px;
          .search-inner-item {
            .item-label {
              height: 30px;
              line-height: 30px;
              font-size: 14px;
              color: #A6A6A6;
              font-weight: 400;
            }
            .el-input {
              position: relative;
              .el-input__inner {
                border: none;
                padding: 0;
              }
              &:after {
                content: "";
                height: 1px;
                background-color: #E2E3E8;
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
              }
            }
          }
        }
        .course-search-btn {
          text-align: center;
          display: block;
          float: none;
          height: 56px;
          line-height: 56px;
        }
      }
    }
    .common-btn {
      display: flex;
      height: 36px;
      line-height: 36px;
      margin-bottom: 10px;
      .btn-title {
        flex: 1;
        font-size: 16px;
        font-weight: bold;
        font-family: PingFangSC-Medium;
        color: rgba(51, 51, 51, 1);
      }
    }
    .common-search-inner {
      padding-top: 10px;
      .search-inner-item {
        .item-label {
          height: 30px;
          line-height: 30px;
          font-size: 14px;
          color: #a6a6a6;
          font-weight: 400;
        }
        .el-input {
          position: relative;
          .el-input__inner {
            border: none;
            padding: 0;
          }
          &:after {
            content: "";
            height: 1px;
            background-color: #e2e3e8;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
          }
        }
      }
    }
    .common-search-btn {
      text-align: center;
      display: block;
      float: none;
      height: 56px;
      line-height: 56px;
    }
    .el-dialog {
      .el-dialog__body {
        padding: 20px;
      }
      .el-dialog__footer {
        border-top: 1px solid #E2E3E8;
        padding: 15px 20px;
      }
    }
  }
  .view-content{
   
    height: 400px;
    overflow: auto;
   
    ul{
      list-style: none;
      margin-block-start: 0em;
      margin-block-end: 0em;
      margin-inline-start: 0px;
      margin-inline-end: 0px;
      padding-inline-start: 0px;
      li{
        border-bottom: 1px solid #efefef;
        p{
          .label-style{
            font-weight: 600;
            color: #333;
          }
          color: #888;
          img{
            width: 100%;
          }
        }
        p:nth-child(1){

        }
      }
    }
     .one{
      width: 400px;
      display: flex;
      margin-left: 100px;
    }
   
  }
   
  /*滚动条样式*/
.el-table__header{
    background: rgb(247, 247, 248) ;
    width: 100%  !important;
  }
  .el-table__body{
    width: 100% !important;
  }
</style>
<style lang="scss">
// ::-webkit-scrollbar {
//   /*滚动条整体样式*/
//   width : 5px;  /*高宽分别对应横竖滚动条的尺寸*/
//   height: 1px;
// }
// :-webkit-scrollbar-thumb {
//   /*滚动条里面小方块*/
//   border-radius: 10px;
//   box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.1);
//   background   : #efefef;
// }
// ::-webkit-scrollbar-track {
//   /*滚动条里面轨道*/
//   box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.1);
//   border-radius: 10px;
//   background   : #ededed;
// }
</style>
